<template>
    <div>
        <table class="table table-bordered">

            <tr>
                <td>商品名称</td>
                <td>
                    <input type="text" v-model="add.name" disabled>
                </td>
            </tr>
            <tr>
                <td>价格</td>
                <td><input type="text" v-model="add.money" disabled></td>
            </tr>
            <tr>
                <td>图片</td>
                <td>
                <td>
                    <input type="file" @change="imga" disabled>
                    <img :src="add.img" width="100" height="100" v-if="add.img != ''">
                </td>
                </td>
            </tr>
            <tr>
                <td>类型</td>
                <td>
                    <select v-model="add.sname" disabled>

                        <option :value="info.sname" v-for="info in list">{{ info.sname }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>要求</td>
                <td>
                    <input type="checkbox" value="保鲜" name="yao" v-model="add.yao" disabled>保鲜
                    <input type="checkbox" value="采销" name="yao" v-model="add.yao" disabled>促销
                    <input type="checkbox" value="买一送一" name="yao" v-model="add.yao" disabled>买一送一
                </td>
            </tr>
            <tr>
                <td>生产时间</td>
                <td>
                    <input type="date" v-model="add.time1" disabled>
                </td>
            </tr>
            <tr>
                <td>过期时间</td>
                <td>
                    <input type="date" v-model="add.time2" disabled>
                </td>
            </tr>
            <tr>
                <td>商品状态</td>
                <td>
                    <input type="radio" :value="true" v-model="add.style" disabled>上架
                    <input type="radio" :value="false" v-model="add.style" disabled>下架
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from "vue";
import moment from 'moment';
import { useStore } from '@/stores/kll';
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
const a = useStore();

let add: any = reactive(
    {
        "id": route.query.id,
        "name": "",
        "money": "",
        "img": "",
        "sname": "",
        "yao": [],
        "time1": "",
        "time2": "",
        "style": true,
        "isdel": true,

    }
)
const imga = (e: any) => {
    console.log(e);
    let obj = e.target.files[0];
    let f = new FormData();
    f.append('file', obj);

    axios({
        url: 'https://localhost:7298/api/Emp/ImgAdd',
        method: 'post',
        data: f
    })
        .then(res => {
            console.log(res);
            add.img = res.data;
        })
        .catch(err => {
            console.log(err);

        })
}
let list: any = ref([]);
const bing = () => {
    axios({
        url: 'https://localhost:7298/api/Emp/bind',
        method: 'get',
        params: add
    })
        .then(res => {
            console.log(res);
            list.value = res.data;
        })
        .catch(err => {
            console.log(err);

        })
}
onMounted(() => {
    bing();
    ft();
})
const ft = () => {
    axios({
        url: 'https://localhost:7298/api/Emp/ft',
        method: 'get',
        params: {
            id: route.query.id
        }
    })
        .then(res => {
            console.log(res);
            Object.assign(add, res.data);
            add.time1 = res.data.time1.substring(0,10);
            add.time2 = res.data.time2.substring(0,10);
            add.yao = res.data.yao.split(',');
        })
        .catch(err => {
            console.log(err);

        })
}
</script>

<style scoped></style>